﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarehouseWebAPP.code.DAL;
using WarehouseWebAPP.code.DAL.VendorDSTableAdapters;

namespace WarehouseWebAPP.code.BLL
{
    public class VendorBLL
    {
        private vendorTableAdapter VendorAdapter = null;

        public vendorTableAdapter Adapter
        {
            get
            {
                if (VendorAdapter == null) VendorAdapter = new vendorTableAdapter();
                return VendorAdapter;
            }
        }
        public VendorDS.vendorDataTable VendorGet()
        {
            return Adapter.GetData();
        }

        public void VendorInsert(string vendor_name)
        {
            if (vendor_name == null)
                throw new Exception("Vendor name is missing");
            if (Adapter.VendorInsert(vendor_name) < 1)
                throw new Exception("Vendor was not added");
        }

        public void VendorUpdate( Guid vendor_num,string vendor_name)
        {
            if (vendor_name == null)
                throw new Exception("Vendor name is missing");
            if (Adapter.VendorUpdate(vendor_name, vendor_num) < 1)
                throw new Exception("Vendor was not updated");
        }

        public void VendorDelete(Guid vendor_num)
        {
            if (Adapter.VendorDelete(vendor_num) < 1)
                throw new Exception("Vendor was not deleted");
        }

        public bool VendorExist(string vendor_name)
        {
            if (Adapter.VendorExists(vendor_name) !=null) return true;
            else return false;
        }

        public VendorDS.vendorDataTable VendorGetByName(string vendor_name)
        {
            if (vendor_name == null)
                throw new Exception("Vendor name is missing");
            return Adapter.VendorGetByName(vendor_name);
        }

        public VendorDS.vendorDataTable VendorGetByNum(Guid verndor_num)
        {
            return Adapter.VendorGetByNum(verndor_num);
        }

    }
}
